// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Core;
using Elastic.Clients.Elasticsearch.Serialization;
using Elastic.Transport;
using System;
using System.Runtime.Serialization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Inference;

[JsonConverter(typeof(TaskTypeConverter))]
public enum TaskType
{
	[EnumMember(Value = "text_embedding")]
	TextEmbedding,
	[EnumMember(Value = "sparse_embedding")]
	SparseEmbedding,
	[EnumMember(Value = "rerank")]
	Rerank,
	[EnumMember(Value = "completion")]
	Completion
}

internal sealed class TaskTypeConverter : JsonConverter<TaskType>
{
	public override TaskType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		var enumString = reader.GetString();
		switch (enumString)
		{
			case "text_embedding":
				return TaskType.TextEmbedding;
			case "sparse_embedding":
				return TaskType.SparseEmbedding;
			case "rerank":
				return TaskType.Rerank;
			case "completion":
				return TaskType.Completion;
		}

		ThrowHelper.ThrowJsonException();
		return default;
	}

	public override void Write(Utf8JsonWriter writer, TaskType value, JsonSerializerOptions options)
	{
		switch (value)
		{
			case TaskType.TextEmbedding:
				writer.WriteStringValue("text_embedding");
				return;
			case TaskType.SparseEmbedding:
				writer.WriteStringValue("sparse_embedding");
				return;
			case TaskType.Rerank:
				writer.WriteStringValue("rerank");
				return;
			case TaskType.Completion:
				writer.WriteStringValue("completion");
				return;
		}

		writer.WriteNullValue();
	}
}